﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;
using System.Windows.Media.Imaging;
using ClimateControl.Infrastructure;

namespace ClimateControl.Controls.Converters
{
    public class StateToStatusConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            string status = string.Empty;

            if (values == null || values.Length == 0 || !(values[0] is State))
                return status;

            State state = (State)values[0];
            Vote vote = values[1] as Vote;

            switch (state)
            {
                case State.Connecting:
                case State.Waiting:
                    status = "Connecting...";
                    break;
                case State.Ready:
                    status = "Ready.";
                    break;
                case State.SendingVote:
                    status = "Sending vote...";
                    break;
                case State.VoteSent:
                    status = string.Format(CultureInfo.CurrentCulture, "Vote sent. {0}", vote == null ? string.Empty : GetVoteMessage(vote.VoteOption));
                    break;
                case State.Upgrading:
                    status = "Upgrading...";
                    break;
            }

            return status;
        }

        private static string GetVoteMessage(VoteOption vote)
        {
            string message = string.Empty;

            switch (vote)
            {
                case VoteOption.TooHot:
                    message = "Woah.";
                    break;
                case VoteOption.TooCold:
                    message = "Brrr.";
                    break;
                case VoteOption.Perfect:
                    message = "Smug.";
                    break;
            }

            return message;
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
